<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui/lib/layui-v2.5.5/css/layui.css" media="all">
</head>
<body>
<form class="layui-form">
    <input type="hidden" name="id"value="{{ $rows['id'] }}">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" required lay-verify="required"value="{{ $rows['username'] }}" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required"value="{{ $rows['password'] }}" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="name" required lay-verify="required"value="{{ $rows['name'] }}" placeholder="请输入真实姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <input type="radio" name="sex" value="1" title="男"@if($rows['sex']==1)checked @endif>
            <input type="radio" name="sex" value="0" title="女"@if($rows['sex']==0)checked @endif>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择角色</label>
        <div class="layui-input-inline">
            <div id="demo1" class="xm-select-demo"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script src="/layui/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/xm-select.js"></script>
<script>
    layui.use(['form', 'table','jquery'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        form.on('submit(formDemo)', function (data) {
            var result = data.field;
            $.ajax({
                url : "/admin/user_update",
                type : "post",
                async: false , //改为同步
                data:{'_token':'{{ csrf_token() }}',result},
                success : function(data) {
                    if(data==1){
                        parent.layer.closeAll();
                        parent.location.reload();
                    }
                },
            });
        });
        $(function(){
            $.post('/admin/user_role_select/{{$rows['id']}}',{'_token':'{{ csrf_token() }}'},function(res){
                var demo1 = xmSelect.render({
                    el: '#demo1',
                    tips: '请选择角色',
                    name: 'role_id',
                    radio: true,
                    clickClose: true,
                    prop: {
                        name: 'role_name',
                        value: 'id',
                    },
                    data: res
                })
            })
        });
    });
</script>
</html>